import { createApp } from 'vue'
import App from './App.vue'
import 'element-plus/dist/index.css'
import 'virtual:svg-icons-register'
import Vue3Marquee from 'vue3-marquee'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { Lazyload } from 'vant'
import { createPinia } from 'pinia'
import "lib-flexible-computer";
import router from './router'
import useTokenStore from './vendors/store/token'
import useSettingStore from './vendors/store/setting'
import 'default-passive-events'
import ws from '@/vendors/ws'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  // import all element icons
  app.component(key, component)
}
app.use(createPinia())
app.use(router)
app.use(Lazyload)
app.use(Vue3Marquee)

// 初始化设置token
const tokenStore = useTokenStore()
tokenStore.setToken()

// 初始化环境配置
const settingStore = useSettingStore()
if (import.meta.env.MODE === 'prod') {
  // 生产环境重置环境配置
  settingStore.resetMode(import.meta.env.MODE)
}
settingStore.setEnv()

if (tokenStore.getToken) {
  // token存在时
  ws() // websocket
}
// plugs
router.isReady().then(() => { app.mount('#app') })
